#include <stdio.h>
#include "ofc/DGZipFile.h"

int main(int argc, char *argv[])
{
#ifdef HAVE_DGZIPFILE
  DGZipFile *file1 = [DGZipFile new];
  DGZipFile *file2 = [DGZipFile alloc];
  DText     *str;

  if ([file1 open :"example.gz" :"w"])   // Open a gzip text file for writing, default compression
  {
    if (![file1 writeLine :"First text line for example.gz."])  // Write a text line in the gzip file
      printf("exampel.gz could not be written:%d.\n", [file1 error]);

    if (![file1 writeLine :"Second text line for example.gz."])
      printf("exampel.gz could not be written:%d.\n", [file1 error]);

    [file1 close];
  }
  else
    printf("example.gz could not be opened for writing:%d.\n", [file1 error]);


  [file2 init :"example.gz" :"r"];       // Init and open a gzip file for reading

  if ([file2 isOpen])                    // Check if open succeeded
  {
    while (![file2 isEof])               // Read all lines
    {
      str = [file2 readLine];

      printf("%s\n", [str cstring]);

      [str free];
    }

    [file2 close];

    printf("example.gz succesfull read.\n");
  }
  else
    printf("example.gz could not be opened: %d\n", [file2 error]);

  [file1 free];                        // Cleanup
  [file2 free];
#else
  printf("DGZipFile is not present in the library.\n");
#endif
  return 0;
}

